use "$Replication\OriginalDataSet.dta", clear
				// Sample sizes of cohort 2 by year.
				tab Study_Arm if Cohort==2 & Year=="2014" & Study_Arm!=98, matcell(G3_full_2014)
				tab Study_Arm if Cohort==2 & Year=="2015" & Study_Arm!=98, matcell(G3_full_2015)
				tab Study_Arm if Cohort==2 & Year=="2016" & Study_Arm!=98, matcell(G3_full_2016)
				tab Study_Arm if Cohort==2 & Grade_Level_On_Track==3 & Study_Arm!=98, matcell(G3_full)
			// Dropped due to missing endline scores
				use "$modified/NonSelectedData.dta", clear // Created in the Create Variable do-file
				tab Study_Arm if Cohort==2 & Grade_Level_On_Track==3 & Study_Arm!=98 & EL_EGRA_PCA_Index==., matcell(G3_NoY)
				mat G3_NoY = G3_NoY,0,0 // Only one missing in the control group. 
			// Dropped due to missing moderators
				// Compute Missing Moderatos Identifier
				gen aux = BL_EGRA_PCA_Index_nstd if Grade_Level_On_Track == 1
				egen BL_P1 = max(aux), by(PupilID)
				gen miss_BL = (BL_P1==.)
				gen BL_P1_w0 = BL_P1 
				sum BL_P1_w0
				replace BL_P1_w0 = r(min) if BL_P1==.
				gen TeachMale = (Teach_Gender=="2. Male" | Teach_Gender=="Male") if Teach_Gender!=""			
				gen sample_X = 1
				foreach var in BL_P1_w0 miss_BL Gender Age TeachMale Teach_Age Teach_Exper Teach_Years_Schooling overall_enrollment_total  pupil_teacher_ratio_overall plepass_rate overall_number_of_teachers  { 
					replace sample_X = . if `var'==. 
				} 	
				// Count
				tab Study_Arm if Cohort==2 & Grade_Level_On_Track==3 & sample_X!=1 & EL_EGRA_PCA_Index!=., matcell(G3_Xno)
			// Final Sample
				tab Study_Arm if Cohort==2 & Grade_Level_On_Track==3 & sample_X==1 & EL_EGRA_PCA_Index!=., matcell(G3_Xyes)
			// Fix Table
			mat G3_NoY   = G3_full - G3_Xno - G3_Xyes
			mat attrited = G3_full_2014 - G3_full
				mat sample_desc = G3_full_2014'\attrited'\G3_NoY'\G3_Xno'\G3_Xyes'			
				svmat sample_desc
				egen total = rowtotal(sample_desc*) if sample_desc3!=.
				gen     names = "P1 Students in 2014" in 1
				replace names = "\quad \quad \quad Attrited Before Endline" in 2
				replace names = "\quad \quad \quad Missing Endline Scores" in 3
				replace names = "\quad \quad \quad Missing Moderators" in 4
				replace names = "Main Analysis Sample" in 5
			// Export
				tostring sample_desc* total, format(%12.0fc) replace force
				keep names sample_desc* total 
				order names sample_desc* total 
				
	save "$output/AppendixTable1.dta", replace			
